﻿Public Class FormOptions

    Private options As ApplicationSettings

    Private Sub FormOptions_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        options = New ApplicationSettings
        FileHandler.LoadOptions(options)
        txtLocation.Text = options.PsxfinExePath
        cboAspectRatio.SelectedIndex = options.AspectRatio
        txtWindowSize.Text = options.WindowSize
        cboWindowSize.SelectedItem = TryCast(options.WindowSize, Object)
        cboCpuPriority.SelectedIndex = options.CpuPriority
        chkHideLogWindow.Checked = options.HideLogWindow
    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        options.PsxfinExePath = txtLocation.Text
        options.AspectRatio = cboAspectRatio.SelectedIndex
        options.CpuPriority = cboCpuPriority.SelectedIndex
        options.WindowSize = txtWindowSize.Text
        options.HideLogWindow = chkHideLogWindow.Checked
        FileHandler.SaveOptions(options)
        If Not IO.File.Exists(options.PsxfinExePath) Then
            MsgBox("The path to psxfin.exe must exist to continue.", MsgBoxStyle.Information)
            Exit Sub
        End If
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        If Not IO.File.Exists(options.PsxfinExePath) Then
            MsgBox("The path to psxfin.exe must exist to continue.", MsgBoxStyle.Information)
            Exit Sub
        End If
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub cboWindowSize_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboWindowSize.SelectedIndexChanged
        If cboWindowSize.SelectedIndex = 0 Then
            txtWindowSize.Enabled = True
            txtWindowSize.Text = "640x480"
        Else
            txtWindowSize.Enabled = False
            txtWindowSize.Text = cboWindowSize.SelectedItem.ToString
        End If
    End Sub

    Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
        Dim dlgOpen As New OpenFileDialog
        dlgOpen.FileName = "psxfin.exe"
        dlgOpen.Filter = "psxfin.exe|psxfin.exe"
        If dlgOpen.ShowDialog = Windows.Forms.DialogResult.OK Then
            txtLocation.Text = dlgOpen.FileName
        End If
    End Sub

End Class
